<?php
/*
 *      nwmenu.php
 *      
 *      Copyright 2010 Vitaliy Rakitin <virak@ukr.net>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
require_once("./classes/GUI/nwmsg.php");
require_once("./config.php");
require_once("./classes/GUI/nwnavigator.php");
require_once("./classes/System/osmetadata.php");


class nwmenu {
	
	private $body;
	private $uuid;

	function __construct() {
		$this->uuid = UUID_NWMENU;
		$_SESSION[$this->uuid] = &$this;
		$this->body = "<div align=left><table><tr>";
		$this->body .= "<td><div align=left><input type='button' name='Dictionaries' value='Словари' onclick=message('$this->uuid','onclick','Dictionaries','');></div></td>";
		$this->body .= "<td><div align=left><input type='button' name='Documents' value='Документы' onclick=message('$this->uuid','onclick','Documents','');></div></td>";
		$this->body .= "<td><div align=left><input type='button' name='Registers' value='Регистры' onclick=message('$this->uuid','onclick','Registers','');></div></td>";
		$this->body .= "</tr></table></div>";
	}

/*
	function docnavi() {
		$out = "<div align=left><table>";
		foreach($GLOBALS["metadata"]->objects->getall("osdocument") as $doc) {
			$out .= "<tr><td><input type='button' name='".$doc["name"]."' value='".$doc["name"]."' onclick=message('$this->uuid','showme','".$doc["id"]."','');></td></tr>";
		}
		$out .= "</table></div>";
		return $out;
	}
*/
	
	function dicnavi() {
		$out = "<div align=left><table>";
		foreach($GLOBALS["metadata"]->dictionaries->getall() as $dic) {
			$out .= "<tr><td><input type='button' name='".$dic->name."' value='".$dic->name."' onclick=message('$this->uuid','showdic','".$dic->uuid."','');></td></tr>";
		}
		$out .= "</table></div>";
		return $out;
	}
	
/*
	function getnavi($type) {
		$out = "<div align=left><table>";
		foreach($GLOBALS["metadata"]->objects->getall($type) as $obj) {
			$out .= "<tr><td><input type='button' name='".$obj["name"]."' value='".$obj["name"]."' onclick=message('$this->uuid','showme','".$obj["id"]."','');></td></tr>";
		}
		$out .= "</table></div>";
		return $out;
	}
*/
	
	function showdic($uuid) {
		$GLOBALS["metadata"]->dictionaries->byuuid($uuid)->defaultlistform->show();
	}
	
	function showme($uuid) {
		$GLOBALS["metadata"]->objects->byuuid($uuid)->listform->show();
	}
	
	function onclick($param1, $param2) {
		switch ($param1) {
			//case "Documents": { $_SESSION[UUID_NWNAVIGATOR]->change($this->docnavi()); break;}
			case "Dictionaries": { $_SESSION[UUID_NWNAVIGATOR]->change($this->dicnavi()); break;}
			//case "Registers": { $_SESSION[UUID_NWNAVIGATOR]->change($this->getnavi("osaccregister")); break;}
		}	
	}
	
	function get() {
		$out = "<fieldset id='".$this->uuid."'><legend><b>Меню</b></legend>";
		$out .= $this->body;
		$out .= "</fieldset>";
		return $out;
	}
	
	function update() {
		$answer = &$_SESSION['answer'];
        $answer[] = array('update',$this->uuid,$this->get());
	}
	
}

?>
